home *** CD-ROM | disk | FTP | other *** search
- ╫ Hi. Welcome to 'Open Prolog'.
-
- This information refers to version 1.0d26.
- Please read it carefully, especially the section on workarounds at the end.
- This is a development version of the software, so it has bugs!
- Save your work often.
-
- Changes from previous versions are listed at the end of the file.
-
- ╫ Introduction
-
- Open Prolog is an implementation of Edinburgh-style Prolog.
-
- For information on Prolog itself, refer to one of the standard textbooks,
- for instance 'Programming in Prolog' by Clocksin & Mellish,
- 'Introduction to Logic Programming' by Christopher Hogger, or the
- excellent 'Artificial Intelligence through Prolog' by Neil C. Rowe.
- (Titles are approximate.)
-
- Open Prolog supports most of the features of DEC Prolog or C-Prolog,
- including Definite Clause Grammars. Real-number arithmetic isn't supported.
- The 'logical' assert and retract semantics of Lindholm & O'Keefe are
- implemented.
- Last Call Optimisation (often called Tail Recursion Optimisation) is done,
- and indexing on the first argument of clause heads is performed,
- mainly to detect determinacy so as to improve memory utilisation.
-
- Open Prolog is called 'Open' because 'external' predicates can be dropped into
- it via a Hypercard-like External Predicate Interface.
-
- Open Prolog is not copy protected.
-
- ╫ System & Memory Requirements
- Open Prolog runs in machines having System 6 (or later) system software.
- If you try to run using an older system, it will complain.
- This means that it won't run in anything 'less' than a Mac Plus.
- Open Prolog is System 7 compatible.
-
- Open Prolog will run under Multifinder in a memory allocation of
- 600K bytes or a bit less. 1024K bytes is recommended.
- For most programs, more than 1024K won't improve performance much.
-
- Open Prolog will run very comfortably on a 1MB machine with
- Multifinder off. If you can't start up in a 1MB machine with Multifinder off,
- check that you haven't got too big a cache set (64k should be adequate),
- and/or too many Startup (INIT) Documents.
-
- All memory management and garbage collection is automatic. The
- name table is not garbage-collected, so it's possible to overflow it.
-
- For the maximum amount of information about errors, put the file
- SysErrs.Err in your System Folder.
-
- For your information, the development environment is a Mac IIx with 8MB Ram.
- Testing is also done on a Mac Plus with 4MB Ram. Systems are 6.0.3 & 7.0.1.
-
- ╫ Speed
- Open Prolog runs the naive reverse benchmark at about 1900 Lips
- on a Macintosh Plus. That means that it's about as fast - maybe even
- a little faster - on a Mac Plus than C-Prolog on a Vax 11/780.
- On a Quadra 900 (or 700), it runs at 35000 Lips. So, it
- runs almost as fast as _compiled_ Dec Prolog ran on a DEC2060.
-
- ╫ About Open Prolog╔
- The 'About Open Prolog╔' box contains a stacks indicator which
- shows memory space broken into
- Name (atom & functor), Code, Global, Local & Trail spaces.
- It's possible to watch the stacks grow and contract as the program runs,
- but keeping the stacks indicator up-to-date slows execution quite a bit!
- To avoid the speed penalty, it's possible to open and close the box while
- the interpreter is running.
- Alternatively, hiding the stacks indicator fully is just as effective.
-
- ╫ Installing Open Prolog
- Open Prolog can be run from floppy, hard disk, or file server. It may be in a locked
- or read-only volume. I haven't tried to use it simultaneously from a server in
- multiple machines - let me know how you do!
- For error messages, please place the file 'Syserrs.Err' in the system folder of
- your own machine.
-
- ╫ Using Open Prolog
- Open Prolog is a text-oriented Prolog. If you have used DEC Prolog or
- C-Prolog, then the style of use of Open Prolog is quite similar.
- The Worksheet is the rough equivalent of their log file.
- It's better because you can re-use chunks of it.
- Standard input and output use the Worksheet by default.
-
- ╫ Startup
- You can start Open Prolog either by opening some of its documents
- or by opening the application itself.
-
- ╫ Home Folder
- A 'Home Folder' is chosen automatically as follows:
- If you start Open Prolog by opening some of its documents, then the folder the documents are in becomes the Home Folder.
- If you start Open Prolog by opening it directly, then the folder it's in
- becomes the Home Folder.
- You can make any folder the Home Folder by saving the Worksheet
- into it. See the section on File Naming for the significance of the
- Home Folder.
-
- ╫ Startup Folder
- The Startup Folder is the folder Open Prolog is in when it is launched.
-
- ╫ Startup Actions
- Before opening any files that you may have selected on the desktop,
- Open Prolog will open a Worksheet in the home folder, always called
- 'Open Prolog Worksheet'.
- Open Prolog does a few other things at startup:
- It looks in the startup folder for a file called 'Open Prolog Options',
- and if it exists, it is consulted.
- It looks in the home folder for a file called 'Open Prolog Startup' and if
- it exists, it is consulted.
- These files can be used to do routine things at startup, if desired.
- Open Prolog Options should contain generally useful stuff, whereas
- Open Prolog Startup, being specific to a folder, can contain more specialised
- startup stuff.
- For example, in this distribution of Open Prolog, a clause in
- the Open Prolog Startup file checks for the existence of this file -
- Open Prolog Info - and displays an alert message in a box.
- So, if this folder is the Home Folder, then the Open Prolog Startup file will
- be consulted, and you'll get the alert message.
-
- Once the startup phase is finished, you are free to edit these files in the
- normal way - there's nothing special about them.
-
- Note that (effective from 1.0d25) while Open Prolog Options is being consulted during
- startup, the default folder for files is the startup folder rather than the home folder.
- This facilitates automatic startup with multiple files.
-
- ╫ Usage
- It helps to visualise the system as having two distinct parts -
- the text editor and the Prolog interpreter.
-
- ╫ Text Editor
- Your interaction with Open Prolog is via the text editor. With it, you can do
- text-editing things on the Worksheet, and on up to seven other files.
- Facilities offered are standard. Worth mentioning is 'Auto-indent'
- which, if enabled, works by copying all the spaces & tabs from the start
- of the previous line down to the start of this line. Also worth mentioning is
- the 'Search All Windows' in the Find and Replace menus. All windows will
- be searched, in front-to-back order, until a match is found. The window in
- which the match is found becomes the front window.
- An open diamond - ╫ - appears opposite the name of the current front window
- in the Window menu. Underlining indicates that the window needs to be
- saved (either it's been changed, or it was never saved before).
- The 'Display Selection' menu will scroll the caret or the selected text into
- view.
- It's possible that Open Prolog won't allow you to open a window because it hasn't
- enough memory. To get around this, enter the built-in predicate 'gc'.
- This should free up some space for more windows.
-
- ╫ Window Characteristics
- When windows are opened, they are opened in the same location (assuming
- it's still visible), and with the same size as when they were
- last closed.
- Likewise, font, font size and the position of the flashing caret or selection
- point are remembered from when the window was last used.
- A window's maximum size if fixed according to the size of the
- printable page in the currently selected printer.
-
-
- ╫ Locked Files
- ***Note - treatment of locked files & volumes doesn't work properly at the moment.
- If a file is locked, or its volume is locked, you can use the window
- as normal, but you won't be allowed to save changes to that file.
-
- ╫ Worksheet
- Most of the transactions that occur between you and Open Prolog will be
- through a window. Generally, you issue commands by typing them into a
- window and then notifying the interpreter about them (using the Enter key),
- and Open Prolog sends replies into the same window.
- You can use any window for this, but the Worksheet will be chosen by default
- or if any errors occur in using another window.
- The Worksheet can't be closed.
-
- ╫ The 'Enter' Key
- To communicate with the Prolog interpreter, you need to notify it in some
- way that what you're doing is not just text editing. This is the function of
- the 'Enter' key: all input from the text editor to the interpreter
- is denoted by selecting the text and typing the <ENTER> key.
- (This is similar to the arrangement in Apple's excellent MPW).
-
- For example, below is the text of a command to consult the file 'benchmarks'.
- To input it to the interpreter, select it (include the full stop) and
- type the <ENTER> key:
-
- [benchmarks].
-
- Actually, you don't always have to select the whole thing; if the text
- occupies only one line, position the cursor anywhere along it and type <ENTER>.
- The whole line will then be taken as the text. This is called
- 'single line selection'.
-
- Remember also that you need to use the <ENTER> key to denote any input to the
- interpreter, not just command input.
-
- Try evaluating the following query by single-line-selecting it.
- You'll need to provide a further input in response; again, you
- can use single line selection. Also, remember the full stop after
- the term:
-
- write('Please enter a Prolog term: '),read(Term),write('It''s: '),write(Term).
-
- As is normal on DEC Prolog, where variable bindings are given as part
- of the result of a query, the system waits for confirmation - type the
- <ENTER> key - or a request for a retry - type a semicolon and the <ENTER> key.
-
- ╫ Prompts
- The standard ?- prompt generally appears on the 'status bar'
- at the top of the front window.
- If you wish, you can enter a query preceded by a ?- - it won't make any
- difference. If you precede your query by a :- then it will be performed
- without returning the variable bindings.
-
- Examples:
- :- write(H),nl.
- ?- write(G).
-
- ╫ Comment on <ENTER> & Prompts
- Using the <ENTER> key to denote input to the interpreter has many advantages,
- although it's probably a bit annoying to get used to.
- The principal advantage is that you can do standard
- text-editing freely and you can use any part of the Worksheet as
- a source of input. In other words, you can re-use text on the Worksheet
- over and over.
- (Some people have complained that there isn't an ENTER key of their
- machines. IN fact, there is one on every machine. Sometimes it has a symbol like
- an arrowhead pointing upwards to meet a horizontal line.) On compact keyboards
- it is usually the strange key to the right of the space bar.
-
- ╫ Syntax Errors
- When Open Prolog tries to read a term, either as a result of your program
- or built-in predicates like consult, if it detects any errors, it will try to
- notify you in a useful way. An error message is written to the output window.
- The part of the error message that begins:
- :- 'Show Syntax Error'(╔
- has the form of a Prolog commands, and can be used to call the
- 'Show Syntax Error' built-in predicate,
- which will try to open the file and show where the error was.
- You use it by single-line-selecting it.
- Try it by consulting the file 'buggy syntax' which has a
- deliberate error:
-
- ['buggy syntax'].
-
- If the file is already open under a different (window) name, or if the file is
- too big, the call will fail.
-
- ╫ Activity During Evaluation
- During a long evaluation, it's still possible to use the
- text editor in windows other than the current output window (which
- is usually the Worksheet). The system will share
- the processor between the interpreter and the text editor.
- Generally, you won't notice the sharing being done.
- Occasionally, however, the interpreter will keep the processor
- for a few seconds to do garbage collection, or I/O.
- During that time the text editor will 'freeze' and won't respond to
- the keyboard or other user input.
- This is normal and is no cause for concern.
-
- Please be careful to save your work frequently in this mode,
- because if the evaluation causes Open Prolog to crash,
- your work may be lost.
-
- ╫ Stopping an Evaluation
- The standard 'Command-.' will halt a Prolog evaluation (eventually!).
-
- ╫ Background Operation
- Open Prolog is Multifinder 'friendly' and will run in the Multifinder
- background. This may be useful for long evaluations. Running under System 7,
- it can be hidden and still be running.
-
- ╫ Operation on portable Macintoshes
- One complication regarding portable Macs is that
- during periods of longer than about 15 seconds without any
- user interaction or cursor animation, portables may go into 'rest' mode.
- In this mode, battery power is conserved by running about 15 times slower than
- normal.
- Open Prolog spins a cursor during long evaluations to prevent resting.
- However, if you are text-editing during an evaluation, the cursor will be
- the I-beam, and it won't be animated; if you pause typing for more
- than about 15 seconds, then the machine will rest.
- Note that you can also prevent a portable from resting using the Control Panel 'Portable' tool - consult your manual.
-
- ╫ Built-In Predicates
- To get a list of all predicates - normal, built-in and external,
- there follows a sequence of commands to perform.
- Select them all and hit the <ENTER> key:
-
- 'system$predicate'(X,Y,Z),functor(Y,X,A),
- writeq(X),write('/'),write(A),write(.),write(' % '),write(Z),nl,fail.
-
- Note: with a few exceptions, you should stay away from
- anything with a $ in it, or anything with the word 'system' in it - you
- may end up crashing the program.
-
- The file 'Open Prolog Extras' has more information about
- the non-standard predicates.
-
- ╫ Redefining Built-In Predicates
- Open Prolog misbehaves if you try to redefine any built-ins or externals.
-
- ╫ Arithmetic
- Arithmetic is standard 32-bit integer arithmetic. The following
- predefined functions are provided:
- unary minus: -
- subtraction: -
- addition: +
- multiplication: *
- integer division: /
- mod (remainder): mod
- bitwise and: /\
- bitwise or: \/
- bitwise not: ~
- bitwise leftshift: <<
- bitwise rightshift: >>
- maximum integer: maxint
- minimum integer: minint
- time: cputime
- The function 'cputime' gives the time in milliseconds since system startup
- with a short-term granularity of approximately 16 mS (one system 'tick').
- Use the built-in procedure 'system$seconds'(Seconds) for more
- accurate timing of long intervals.
-
- ╫ Operators
- The standard DEC Prolog operator definitions are made at startup.
- You can get a list of operator definitions by evaluating the following query.
-
- current_op(X,Y,Z),write(op(X,Y,Z)),write('.'),nl,fail.
-
- ╫ Extended Character Set
- The full laser-printer character set (e.g. Times), which has more
- characters than the original standard character sets like Chicago,
- is assumed here.
-
- Accented characters are treated as alphabetic, so atoms containing
- accented characters don't need to be put in quotes.
-
- Thus the following is legal:
-
- Xèvier = nùirÆn+jƒrgen+âcole+grÅve+da¢+ìedilla+forÉt.
-
- ╫ Sorting
- Sorting is performed by the Mac's International Utilities, which
- should handle accented characters correctly.
- Note that case is ignored when sorting functor or atom names.
-
- ╫ Files
- The file-handling arrangements are essentially unchanged from DEC Prolog,
- except where obviously necessary. Some built-in predicates have been
- omitted, notably 'close/1' and 'fileErrors' & 'nofileerrors'.
-
- ╫ File Naming
- File naming follows standard Mac practice. To specify a file in the
- home folder, just give its name (as 'benchmarks' above).
-
- If it's in another folder, you can give its full pathname. For example, to
- consult a file called 'Utilities' on a disk or volume called 'Open Prolog Disk'
- in a folder called 'Samples' you could use:
-
- ['Open Prolog Disk:Samples:Utilities'].
-
- Alternatively, you can specify a file by its partial pathname (i.e. the extra information needed to 'get from' the Home Folder to there).
- For instance, on this distribution you can use the following to consult
- the file 'Tak' in the folder 'Samples' which is in the Home Folder:
-
- [':Samples:Tak'].
-
- ╫ End of File & End of Line
- - End of line & end of file treatment is the same as in DEC Prolog.
- - When reading from a file, the last term is always 'end_of_file'.
- - When get-ing or get0-ing from a file, the last character is code 26.
- . Carriage Returns (ASCII code 13), generally signifying end-of-line in a file,
- are filtered out of the get or get0 stream and replaced by code 31.
-
- Input from a window never results in an end of file condition.
-
- ╫ nl
- - nl outputs a Carriage Return (ASCII code 13).
-
- ╫ get & get0
- - get & get0 always return the next character, irrespective of whether it is
- 'printable' or not.
-
- ╫ Debugging
- The main Program Debugging facility is the trace/1 predicate.
- You can trace the execution of a predicate by calling it via trace:
-
- %assuming you've already consulted 'tak' above╔
-
- trace(tak(12,8,4,N)).
-
- The commands available are:
- <ENTER> - trace
- s<ENTER> - step over
- a<ENTER> - abort
- f<ENTER> - fail
- @<ENTER> - break for one command
-
- It's not possible to spy.
-
- The unknown/2 predicate specifies what happens when a call is made
- to an unknown predicate. (Allowable values are fail or trace.)
-
- E.g., select:
-
- unknown(X,trace).
-
- This will set Open Prolog to abort when an unknown call is made.
-
- Try it now by selecting:
-
- huh(What).
-
- A snazzy source-level debugger, a lê SADE, is under development.
-
- ╫ System Error Messages:
- There are three kinds of error messages:
- A. A simple information box with 'OK' as the only option.
- B. A 'Diagnostic' or 'Breakpointer' information box.
- This is intended for giving debugging
- information, and if it turns up in normal operation it means that a special
- condition has occured.
- C. Whenever Open Prolog detects a system error, it will warn you about it.
- You are generally given some information about the source and kind of the
- error. Naturally, it isn't always possible to predict what will happen
- if you continue operating the system.
-
- Summarising: When you get an error message,
- if you are given a choice, it's best (initially) to exit.
- You normally get to save your files and windows, although sometimes
- the nature of the error causes more errors to be made as the files &
- windows are being saved. It that happens, you lose your fi╔
- Experience will tell what's best to do in a situation.
- (I sure hope you don't get a lot of that experience╔)
-
- I'd appreciate you mailing me with the circumstances and nature of
- B & C type messages, and of undesirable effects of A type messages.
-
- ╫ Problems with Open Prolog
- Here are the known significant difficulties with Open Prolog at the moment.
- There are simple workarounds for them all.
-
- 1. The absolute maximum size of any file that can be seen in an Open Prolog
- window is limited to 32767 characters.
- Actually the realistic maximum is about 16000.
- This limit only applies to files that you want to open as windows.
- Open Prolog neither truncates window files nor warns you about impending
- problems.
- So, for example, if your program produces large output files, that's OK as
- long as you don't want to open them as windows from Open Prolog.
- Workarounds:
- Break your files into smaller files.
- Trim the Worksheet periodically so that is doesn't get too big.
- To view and process larger text files, you'll need to use a text processor
- (MPW highly recommended) or word processor in text mode (MS Word or
- MacWrite II).
-
- 2. Currently, the window system and the file system are not integrated.
- So, changes you make to a file in a window are not automatically
- reflected in the file when it is being consulted.
- Workaround - after making changes to a file in a window,
- save it before consulting or reconsulting it.
- (Actually, it's a good idea to save your work each time anyway╔)
- Likewise, a window must be closed before your program
- starts to output to it.
- Another difficulty is if you try to open a window & file from a predicate
- and the file is already open into a window of a different name; then the
- system will not recognise the already open window as the one it wants,
- and will refuse to open another.
-
- 3. Tab characters are not properly represented or printed - instead a tab
- always occupies exactly one space. If you intend using your files with
- another text/word processor, then you should put them in╔
-
- 4. The implementation of cuts in a disjunctive call (i.e. ;/2) is not
- according to the impending Prolog standard.
- According to the standard, cut in a disjunction should have the same effect
- as a cut in the disjunction's parent. In Open Prolog, a cut in a disjunction has
- only a local effect.
- Secondly, disjunctive calls are compiled on the fly in Open Prolog, so they are
- much slower than normal code.
- Both these points will be fixed soon.
-
- 5. Similarly to above, a nested conjunctive call has the same problems -
- cuts have only local effects, and the nested calls are compiled on the fly.
-
- ╫ External Predicates
- External predicates are extra predicates written separately from Open Prolog, and
- then 'dropped' in to Open Prolog using something like ResEdit. At present, only an
- MPW Pascal interface is defined, although it would be a trivial job to define an
- MPW C interface (and MPW Assemby) also. A small amount of work would be necessary
- to use THINK Pascal and C.
- In this release, 'system$random', 'say', 'play' and 'system$menu' are external
- predicates. Likewise 'draw' is an external predicate (see separate documentation).
- If you really want to write some external predicates, mail me & I'll send you
- the MPW Pascal files you need together with an example.
- Be aware that it's likely that the interface will change in the future.
-
- ╫ Revision History
- - 1.0d26
- 1. Undo finally implemented!
- 2. Minor cosmetic changes to minimise junk on worksheet.
- 3. You can add menus to Open Prolog. See 'Open Prolog Extras' for details.
- 4. Bug fix - a bug which crashed Open Prolog when a systen predicate was
- stopped by command-. has been removed.
- - 1.0d25 Bug Fixes - name/2 with numbers, serious memory Management
- garbage collection errors fixed. 'system$alert'/1 replaced by 'system$alert'/4
- 'system$confirm'/4 introduced also. Default folder changed on startup - see text.
- - 1.0d24 Bug Fixes (multiple operator definitions, command-.), introduction of a status bar, use of 'Syserrs.err' for error messages╔
- - 1.0d23, 1.0d22 & 1.0d21 Bug Fixes
- -1.0d20
- 1. Add garbage collection to the code space - findall without tears!
- 2. Fix some odd behaviour of the debugger. It seemed to wander off
- sometimes╔
- -1.0d18
- 1. Animated Cursor to stop it resting or sleeping on a long calculation in a
- Portable.
- -1.0d17
- 1. Cosmetic improvements, particularly multi-screen handling.
- 2. New window-handling predicates.
- 3. External Predicate Interface Inprovement
-
- - 1.0d16
- 1. A crash-without-warning bug has been cured.
- 2. A bug in call(X) which declated a call like call((read(X),X)) illegal because
- the second call was uninstantiated has been cured.
- 3. The DCG compiler has been changed a little.
- 4. Various cosmetic improvements.
- 5. A number of extra predicates to handle window I/O have been added.
-
- - 1.0d15
- 1. A restriction which required all <ENTER>ed text (including commands)
- to be on the Worksheet has been removed.
- 2. Sometimes the way in which part of a line was picked for selection
- was a little unpredictable. This has been cured.
- 3. A -192 warning caused by a harmless fault in the System
- when DA Menuz and Suitcase were present has been removed.
-
- - 1.0d14
- Initial Release
-
-